Ext.define('SKJF.view.PENJUALAN.v_poclientdet_form', {
	extend	: 'Ext.form.Panel',
	
	alias	: 'widget.v_poclientdet_form',
	
	//region:'east',
	//id: 'east-region-container',
	
	title		: 'Create/Update poclientdet',
    bodyPadding	: 5,
    autoScroll	: true,
    
    initComponent: function(){
    	/*
		 * Deklarasi variable setiap field
		 */
		
		var mstsatuan_store = Ext.create('SKJF.store.s_mstsatuan',{autoLoad:true});
		var mstbarang_store = Ext.create('SKJF.store.s_mstbarang');
		
		var HARGA_TOTAL_field = Ext.create('Ext.form.field.Number', {
			name: 'HARGA_TOTAL', /* column name of table */
			fieldLabel: 'HARGA_TOTAL',
			readOnly: true
		});
		var HARGA_SATUAN_field = Ext.create('Ext.form.field.Number', {
			name: 'HARGA_SATUAN', /* column name of table */
			fieldLabel: 'HARGA_SATUAN',
			allowBlank: false,
			enableKeyEvents: true,
			listeners: {
				'keyup': function(editor, e){
					var jumlah = Ext.get('JUMLAH').dom.value;
					var total = editor.value * jumlah;
					HARGA_TOTAL_field.setValue(total);
				}
			}
		});
		var JUMLAH_field = Ext.create('Ext.form.field.Number', {
			inputId : 'JUMLAH',
			name: 'JUMLAH', /* column name of table */
			fieldLabel: 'JUMLAH',
			enableKeyEvents: true,
			listeners: {
				'keyup': function(editor, e){
					var harga = HARGA_SATUAN_field.getValue();
					var total = editor.value * harga;
					HARGA_TOTAL_field.setValue(total);
				}
			}
		});
		var NOMOR_PO_field = Ext.create('Ext.form.field.Text', {
			itemId: 'NOMOR_PO_field',
			name: 'NOMOR_PO', /* column name of table */
			fieldLabel: 'NOMOR_PO',
			readOnly: true
		});
		var NAMA_BARANG_field = Ext.create('Ext.form.field.ComboBox', {
			itemId: 'NAMA_BARANG_field',
			name: 'NAMA_BARANG', /* column name of table */
			fieldLabel: 'NAMA_BARANG',
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: mstbarang_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{KODE_BARANG} - {NAMA_BARANG}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{KODE_BARANG} - {NAMA_BARANG}',
				'</tpl>'
			),
			valueField: 'NAMA_BARANG',
			displayField: 'NAMA_BARANG',
		});
		var SATUAN_field = Ext.create('Ext.form.field.ComboBox', {
			name: 'SATUAN', /* column name of table */
			fieldLabel: 'SATUAN',
			pageSize: 10,
			typeAhead    : true,
			triggerAction: 'all',
			selectOnFocus: true,
            loadingText  : 'Searching...',
			store: mstsatuan_store,
			queryMode: 'local',
			tpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'<div class="x-boundlist-item">{NAMA_SATUAN}</div>',
				'</tpl>'
			),
			displayTpl: Ext.create('Ext.XTemplate',
				'<tpl for=".">',
					'{NAMA_SATUAN}',
				'</tpl>'
			),
			valueField: 'NAMA_SATUAN',
			displayField: 'NAMA_SATUAN'
		});
		var TARGET_KIRIM_BRG_field = Ext.create('Ext.form.field.Date', {
			name: 'TARGET_KIRIM_BRG', /* column name of table */
			format: 'Y-m-d',
			fieldLabel: 'TARGET_KIRIM_BRG'
		});
		var ID_field = Ext.create('Ext.form.field.Hidden', {
			name: 'ID', /* column name of table */
			fieldLabel: 'ID',
			readOnly: true
		});
        Ext.apply(this, {
            fieldDefaults: {
                labelAlign: 'right',
                labelWidth: 120,
                msgTarget: 'qtip',
				anchor: '100%'
            },
			defaultType: 'textfield',
            items: [NOMOR_PO_field,NAMA_BARANG_field,JUMLAH_field,SATUAN_field,HARGA_SATUAN_field,HARGA_TOTAL_field,TARGET_KIRIM_BRG_field,ID_field],
			
	        buttons: [{
                iconCls: 'icon-save',
                itemId: 'save',
                text: 'Save',
                disabled: true,
                action: 'save'
            }, {
                iconCls: 'icon-add',
				itemId: 'create',
                text: 'Create',
                action: 'create'
            }, {
                iconCls: 'icon-reset',
                text: 'Cancel',
                action: 'cancel'
            }]
        });
        
        this.callParent();
    }
});